#pragma once

#include <map>

using namespace std;


//-------------------------------TYPE DEFINITION--------------------------------

typedef enum AdpcmSessionType ADPCMSESSIONTYPE;
typedef struct AdpcmSessionInfo ADPCMSESSIONINFO;
typedef map< HAUDIOSESSION, ADPCMSESSIONINFO > SESSIONSTORAGE;

class AdpcmSessionManager
{
public:
	AdpcmSessionManager(void);
	~AdpcmSessionManager(void);

	HAUDIOSESSION CreateCaptureSession(int deviceIndex, int channels, int sampleRate, int bitsPerSample, int bitrate, AudioCodecId codecId, CaptureAudioCallBack callback);
	HAUDIOSESSION CreatePlaybackSession(int channels, int sampleRate, int bitsPerSample, AudioCodecId codecId);

	int PlaybackAdpcmData(HAUDIOSESSION session, char *data, int len);
	int PlaybackAmrData(HAUDIOSESSION session, char *data, int len);
	int SetAdpcmPlaybackVolume(HAUDIOSESSION session, int volume);
	int GetAdpcmPlaybackVolume(HAUDIOSESSION session);
	void PausePlayAdpcmData(HAUDIOSESSION session);
	void ResumePlayAdpcmData(HAUDIOSESSION session);

	int SetAudioCaptureVolume(HAUDIOSESSION session, int volume);
	int GetAudioCaptureVolume(HAUDIOSESSION session);

	void DestroySession(HAUDIOSESSION);
	void DestroyAllSession();

	static int GetCaptureDeviceNum();
	static int GetCaptureDeviceName(int deviceIndex, char *buf, int len);

	int Initialize();
	void Uninitialize();

private:
	static volatile HAUDIOSESSION s_sessionIdSeq;
	static CCritSec s_sessionIdSeqLock;

	SESSIONSTORAGE m_sessionStorage;
	CCritSec m_sessionStorageLock;

	static HAUDIOSESSION GetNewSessionId();

	ADPCMSESSIONINFO *GetSessionInfoByHandle(HAUDIOSESSION);
	HAUDIOSESSION InternalCreateSession(ADPCMSESSIONTYPE type, int channels, int sampleRate, int bitsPerSample, int bitrate, AudioCodecId codecId, CaptureAudioCallBack callback = NULL, int deviceIndex = 0);
};
